package com.yxym.static_;

public class StaticMethod {
    public static void main(String[] args) {
        Student student1 = new Student("jack");
        student1.pay(100);

        Student student2 = new Student("jack");
        student2.pay(200);

        student1.showFee();//总学费
        System.out.println(MyTools.sum(20.0,30.0));

        Student.OK();
    }
}//开发自己的工具类，可以将方法做成静态的
class MyTools{
    public static double sum(double d1, double d2){
        return d1 + d2;
    }
}
class Student{
    private String name;
    private static int n1 = 1;
    public static int n2 = 2;
    public Student(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
    //定义静态变量，来累计学生的学费
    private static double fee = 0;
    public Student(String name) {
        this.name = name;
    }
    //1.当方法使用了static修饰s后，该方法是静态方法
    //2.静态方法可以访问静态属性
    public void pay(double fee){
        Student.fee += fee;//积累
    }
    public void showFee(){
        System.out.println("学费：" + Student.fee);
    }
    public static  void OK(){
        System.out.println(n1);
        System.out.println(n2);//静态方法只能访问静态属性或变量
    }
}